package com.modelo.dao.subtarea;

import java.util.List;

import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

import com.modelo.dao.comun.HibernateBaseDAO;
import com.modelo.entity.Subtarea;

@Repository
public class SubtareaDAO extends HibernateBaseDAO<Subtarea> implements ISubtareaDAO {
	public static final String ENLACE = "enlace";

	public static final String IMAGEN = "imagen";
	private static final Logger log = LoggerFactory.getLogger(SubtareaDAO.class);
	public static final String NOMBRE = "nombre";

	public static SubtareaDAO getFromApplicationContext(ApplicationContext ctx) {
		return (SubtareaDAO) ctx.getBean("SubtareaDAO");
	}

	@Autowired
	public SubtareaDAO(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public List<Subtarea> findByEnlace(Object enlace) {
		return findByProperty(ENLACE, enlace);
	}

	public List<Subtarea> findByExample(Subtarea instance) {
		log.debug("finding Subtarea instance by example");
		try {
			List<Subtarea> results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List<Subtarea> findByImagen(Object imagen) {
		return findByProperty(IMAGEN, imagen);
	}

	public List<Subtarea> findByNombre(Object nombre) {
		return findByProperty(NOMBRE, nombre);
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Subtarea instance with property: " + propertyName + ", value: " + value);
		try {
			String queryString = "from Subtarea as model where model." + propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	@Override
	protected void initDao() {

	}
}